{
 "metadata": {
  "signature": "sha256:fb24bd300a227052865685fd09c783be9e08a2347b0d6a9550309c2e44b74506"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "OLS\n",
      "===\n",
      "\n",
      "OLS is an abbreviation for ordinary least squares.\n",
      "\n",
      "The class estimates a multi-variate regression model and provides a\n",
      "variety of fit-statistics. To see the class in action download the\n",
      "[ols.py](files/attachments/OLS/ols.0.2.py) file and run it (python ols.py). This\n",
      ")# will estimate a multi-variate regression using simulated data and\n",
      "provide output. It will also provide output from R to validate the\n",
      "results if you have rpy installed (http://rpy.sourceforge.net/).\n",
      "\n",
      "To import the class:"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#!python\n",
      "import ols"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "After importing the class you can estimate a model by passing data to it\n",
      "as follows"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#!python\n",
      "mymodel = ols.ols(y,x,y_varnm,x_varnm)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "where y is an array with data for the dependent variable, x contains the\n",
      "independent variables, y\\_varnm, is a string with the variable label for\n",
      "the dependent variable, and x\\_varnm is a list of variable labels for\n",
      "the independent variables. Note: An intercept term and variable label is\n",
      "automatically added to the model.\n",
      "\n",
      "Example Usage\n",
      "-------------"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#!python\n",
      ">>> import ols\n",
      ">>> from numpy.random import randn\n",
      ">>> data = randn(100,5)\n",
      ">>> y = data[:,0]\n",
      ">>> x = data[:,1:]\n",
      ">>> mymodel = ols.ols(y,x,'y',['x1','x2','x3','x4'])\n",
      ">>> mymodel.p               # return coefficient p-values\n",
      "array([ 0.31883448,  0.7450663 ,  0.95372471,  0.97437927,  0.09993078])\n",
      ">>> mymodel.summary()       # print results\n",
      "==============================================================================\n",
      "Dependent Variable: y\n",
      "Method: Least Squares\n",
      "Date: Thu, 28 Feb 2008\n",
      "Time: 22:32:24\n",
      "# obs:             100\n",
      "# variables:         5\n",
      "==============================================================================\n",
      "variable     coefficient     std. Error      t-statistic     prob.\n",
      "==============================================================================\n",
      "const           0.107348      0.107121      1.002113      0.318834\n",
      "x1             -0.037116      0.113819     -0.326100      0.745066\n",
      "x2              0.006657      0.114407      0.058183      0.953725\n",
      "x3              0.003617      0.112318      0.032201      0.974379\n",
      "x4              0.186022      0.111967      1.661396      0.099931\n",
      "==============================================================================\n",
      "Models stats                         Residual stats\n",
      "==============================================================================\n",
      "R-squared             0.033047         Durbin-Watson stat   2.012949\n",
      "Adjusted R-squared   -0.007667         Omnibus stat         5.664393\n",
      "F-statistic           0.811684         Prob(Omnibus stat)   0.058883\n",
      "Prob (F-statistic)    0.520770\t       JB stat              6.109005\n",
      "Log likelihood       -145.182795       Prob(JB)             0.047146\n",
      "AIC criterion         3.003656         Skew                 0.327103\n",
      "BIC criterion         3.133914         Kurtosis             4.018910\n",
      "=============================================================================="
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "== Note ==\n",
      "\n",
      "Library function [http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.lstsq.html numpy.linalg.lstsq()] performs basic OLS estimation."
     ]
    }
   ],
   "metadata": {}
  }
 ]
}